package com.keke.myblogv1.usermessage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keke.myblogv1.common.result.ResponseResult;
import com.keke.myblogv1.usermessage.dto.QueryUserMessageDTO;
import com.keke.myblogv1.usermessage.entity.MyBlogUserMessage;
import com.keke.myblogv1.usermessage.mapper.MyBlogUserMessageMapper;
import com.keke.myblogv1.usermessage.service.MyBlogUserMessageService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Derrick
 * @since 2022-07-31
 */
@RestController
@RequestMapping("/usermessage")
public class MyBlogUserMessageController {

    @Resource
    private MyBlogUserMessageService myBlogUserMessageService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ResponseResult<List<MyBlogUserMessage>> getMyBlogUserMessageList(){
        List<MyBlogUserMessage> myBlogUserMessageList=null;
        try{
            myBlogUserMessageList = myBlogUserMessageService.getMyBlogUserMessageList();
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(myBlogUserMessageList);
    }
    @RequestMapping(value = "/listByPage",method = RequestMethod.GET)
    public ResponseResult<Page<MyBlogUserMessage>> getMyBlogUserMessageListByPage(QueryUserMessageDTO queryUserMessageDTO){
        Page<MyBlogUserMessage> myBlogUserMessageList=null;
        try{
            myBlogUserMessageList = myBlogUserMessageService.getMyBlogUserMessageListByPage(queryUserMessageDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        return ResponseResult.success(myBlogUserMessageList);
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResponseResult updateMessage(@RequestBody MyBlogUserMessage myBlogUserMessage){
        boolean result = false;
        try {
            result = myBlogUserMessageService.updateMessage(myBlogUserMessage);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public ResponseResult insertMessage(@RequestBody MyBlogUserMessage myBlogUserMessage){
        boolean result = false;
        try{
            result = myBlogUserMessageService.insertMessage(myBlogUserMessage);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public ResponseResult deleteMessage(@RequestBody MyBlogUserMessage myBlogUserMessage){
        boolean result = false;
        try{
            result = myBlogUserMessageService.deleteMessage(myBlogUserMessage);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error();
        }
        if(result){
            return ResponseResult.success();
        }else{
            return ResponseResult.error();
        }
    }
}
